package com.heima.article.listener;

import com.alibaba.fastjson.JSON;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.WmNewsMessageConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author ItZheng
 * @Date 2023/6/17 19:42
 * @Version 1.5
 */
@Component
@Slf4j
public class ArtilceIsDownListener {

    @Autowired
    private ApArticleConfigService apArticleConfigService;

    @KafkaListener(topics = WmNewsMessageConstants.WM_NEWS_UP_OR_DOWN_TOPIC)
    public void onMessage(String message){
        //校验参数：
        if (StringUtils.isNotEmpty(message)){


            //将数据反序列化成 Map对象
            Map map = JSON.parseObject(message, Map.class);

            //调用Service修改保存数据
            apArticleConfigService.downOrUp(map);

            log.info("成功接收参数：{}",map);
        }
    }
}
